const { mysql } = require('../qcloud')

module.exports = async (ctx) => {
    const {opinion, src, wechat, openid} = ctx.request.body
    // console.log('后端接收到的数据opinion', opinion)
    // console.log('后端接收到的数据src', src)
    // console.log('后端接收到的数据wechat', wechat)
    // console.log('后端接收到的数据openid', openid)
    try {
        await mysql('opinions').insert({
            opinion, src, wechat, openid
        })
        ctx.state.data = {
            code: 0,
            msg: 'success'
        }
        console.log('执行成功')
    } catch (error) {
        ctx.state = {
            code: -1,
            data: {
                msg: '添加失败' + error.sqlMessage
            }
        }
        console.log('执行错误')
    }
}
